package org.lboot.llog.test;

import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lboot.core.domain.ResponseDTO;
import org.lboot.llog.anno.ApiLog;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author kindear
 * AOP实现类测试接口
 */
@Slf4j
@RestController
@RequestMapping("/llog/test")
@AllArgsConstructor
public class AopTestController {
    private HttpServletRequest request; // 自动注入 request 对象

    @ApiLog("追踪测试")
    @GetMapping("trace")
    @ApiOperation(value = "追踪ID测试")
    public ResponseDTO<Object> testTrace(){
        log.info("追踪ID:{}", request.getAttribute("trace-id"));
        return ResponseDTO.succData("请求成功");
    }

    @ApiLog("错误测试")
    @PostMapping("error")
    @ApiOperation(value = "错误测试")
    public ResponseDTO<Object> testError(){
        // HttpServletRequest request =((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        Integer t = null;
        if (t.equals(1)){
            log.info("ok");
        }
        return ResponseDTO.succMsg("请求成功");
    }
}
